]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
st: Avoid integer overflow on unpremultiply
authorFlorian Müllner <fmuellner@gnome.org>
Thu, 22 Nov 2018 19:41:44 +0000 (20:41 +0100)
committerFlorian Müllner <florian.muellner@gmail.com>
Tue, 4 Dec 2018 15:55:39 +0000 (15:55 +0000)
When computing the effective border color, we operate on colors with
premultiplied alpha to simplify the calculations, then unpremultiply
the result. However we miss a bounds check in the last check, so any
color component can overflow the allowed maximum of 0xff and shift the
result in unexpected ways.

https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/305

src/st/st-theme-node-drawing.c

index 9f7e6b6ca4a4cbfcbcc462e2001ad0489c0e6b5a..a7fb24ab85a4b940e16946028e57169c3608bedc 100644 (file)
@@ -229,9 +229,9 @@ unpremultiply (ClutterColor *color)
 {
   if (color->alpha != 0)
     {
-      color->red = (color->red * 255 + 127) / color->alpha;
-      color->green = (color->green * 255 + 127) / color->alpha;
-      color->blue = (color->blue * 255 + 127) / color->alpha;
+      color->red = MIN((color->red * 255 + 127) / color->alpha, 255);
+      color->green = MIN((color->green * 255 + 127) / color->alpha, 255);
+      color->blue = MIN((color->blue * 255 + 127) / color->alpha, 255);
     }
 }